package com.dot.comm.utils;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class SignTool {
  public static String md5Sign(Object platDataMap, String signkey) throws Exception {
    Map<String, String> hashMap = (Map<String, String>) platDataMap;
    TreeMap<String, String> treeMap = new TreeMap<String, String>();
    for (String key : hashMap.keySet()) {
      treeMap.put(key, hashMap.get(key));
    }
    // 开始验签
    String platSignOrigStr = "";
    String platSignStr = "";
    Set<String> keys = treeMap.keySet();
    for (String key : keys) {
      String value = (String) treeMap.get(key);
      if (StringUtils.isBlank(value)) {
        continue;
      }
      platSignOrigStr = platSignOrigStr + key + "=" + value + "&";
    }
    platSignOrigStr = platSignOrigStr + "key=" + signkey;
//    System.out.println("sign字符串: "+platSignOrigStr);
    platSignStr = MD5Util.MD5Encode(platSignOrigStr);
    return platSignStr;
  }
}
